{$CLEO .qa}
{$USE CLEO+}
{$USE Audio}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "BUMQA"

// By ArtemQa146

const
    bum_man = 31@
    ped_donate = 29@
    Find_Ped = 30@
    Money_render = 28@
    Event = 27@
    coords_x = 26@
    coords_y = 25@
    coords_z = 24@
    angle_1 = 23@
    donate_lvl = 22@
    obj_1 = 21@
end

0087: coords_x = 0@ // (float)
0087: coords_y = 1@ // (float)
0087: coords_z = 2@ // (float)
0087: angle_1 = 3@ // (float)

if
    0E4D: random_percent 4@
then
else
    repeat
    wait 0
    until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 150.0
    0A93: terminate_this_custom_script
end

repeat
wait 0
04ED: load_animation  "PedEventsMod"
until 04EE:   animation "PedEventsMod" loaded

0209: 2@ = random_int_in_ranges 1 10
if 2@ == 1
then 1@ = 77
end
if 2@ == 2
then 1@ = 78
end
if 2@ == 3
then 1@ = 79
end
if 2@ == 4
then 1@ = 134
end
if 2@ == 5
then 1@ = 135
end
if 2@ == 6
then 1@ = 137
end
if 2@ == 7
then 1@ = 212
end
if 2@ == 8
then 1@ = 230
end
if 2@ == 9
then 1@ = 239
end
model.Load(1@)
model.Load(928)

if
    not model.Available(1@)
then
    repeat
    wait 0
    model.Load(1@)
    until model.Available(1@)
end

if
    not model.Available(928)
then
    repeat
    wait 0
    model.Load(928)
    until model.Available(928)
end

038B: load_requested_models
009A: bum_man = create_actor_pedtype 21 model 1@ at coords_x coords_y coords_z
0173: set_actor bum_man Z_angle_to angle_1
0E24: fix_char bum_man ground 1 brightness 1 and_fade_in 0
0812: AS_actor bum_man perform_animation "bum_idle" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1  // versionB
Event = 0
donate_lvl = 0
model.Destroy(1@)
04C4: store_coords_to 1@ 2@ 3@ from_actor bum_man with_offset 0.0 0.8 -0.835
0E01: create_object_no_save 928 at 1@ 2@ 3@ offset 0 ground 0 to obj_1
08D2: object obj_1 scale_model 0.6
0382: set_object obj_1 collision_detection 0
07F7: set_object obj_1 destructible 0
model.Destroy(928)
Money_render = -1

repeat
wait 0
    if
        056D:   actor bum_man defined
    then
    
        // , ,    
        080E: get_actor $PLAYER_ACTOR ped_event_to 2@
        080E: get_actor bum_man ped_event_to 3@
        if or
            actor.Dead(bum_man)
            2@ == 11
            3@ == 49
            3@ == 9
            051A:   actor bum_man damaged_by_actor $PLAYER_ACTOR
            not is_char_script_controlled bum_man
            not $ACTIVE_INTERIOR == 0
        then
            break
        end
        
        080E: get_actor bum_man ped_event_to 2@
        if or
            2@ == 15
            2@ == 31
            2@ == 59
        then
            break
        end
        
        //   
        0E40: get_current_hour 2@
        if or
            not 2@ >= 9
            not 20 >= 2@
        then
            break
        end
        
        //    
        if
            0457:   player $PLAYER_CHAR aiming_at_actor bum_man
        then
            0E83: get_current_char_weaponinfo $PLAYER_ACTOR store_to 2@
            0E89: get_weaponinfo_fire_type 2@ store_to 3@ //     
            if or
                3@ == 1 //  
                3@ == 3 //   (  ..)
            then
                break
            end
        end
        
        //   
        04C4: store_coords_to 2@ 3@ 4@ from_actor bum_man with_offset 0.0 1.5 0.0
        if
            0102:   actor $PLAYER_ACTOR in_sphere 2@ 3@ 4@ radius 1.0 1.0 1.5 sphere 0 stopped_on_foot
        then
            if
                Event == 0
            then
                if
                    010A:   player $PLAYER_CHAR money > 49
                then
                    if
                        8A2A:   not text_box 'donat1' displayed
                    then
                        0512: show_permanent_text_box 'donat1'  // If your health reaches zero, you will pass out and you will be treated at the local medical center.
                    end
                else
                    if
                        8A2A:   not text_box 'donat2' displayed
                    then
                        0512: show_permanent_text_box 'donat2'  // If your health reaches zero, you will pass out and you will be treated at the local medical center.
                    end
                end
            end
            if and
                not Event > 0
                010A:   player $PLAYER_CHAR money > 49
                00E1:   player 0 pressed_key 15
            then
                07CC: set_player $PLAYER_CHAR can_enter_exit_vehicles 0
                04C4: store_coords_to 2@ 3@ 4@ from_actor bum_man with_offset 0.0 0.0 0.0
                04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0
                0E27: get_angle_from_two_coords 5@ 6@ and 2@ 3@ to 4@
                0173: set_actor $PLAYER_ACTOR Z_angle_to 4@
                06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 1
                0992: set_player $PLAYER_CHAR weapons_scrollable 0
                0812: AS_actor $PLAYER_ACTOR perform_animation "SAX3" IFP "PedEventsMod" framedelta 4.0 loopA 0 lockX 1 lockY 0 lockF 0 time -1
                Event = 1
                timerb = 0
                donate_lvl += 1
            end
        else
            gosub @Text_box_remove
        end


        gosub @Event
        
        if and
            Event == 0
            donate_lvl == 0
            0611:   actor bum_man performing_animation "bum_idle"
            timerb > 60000
            0EE4: locate_char_distance_to_char $PLAYER_ACTOR char bum_man radius 15.0
        then
            gosub @Animation_angry
            timerb = 0
        end
        
        //  
        Find_Ped = 0
        while 0EA7: get_any_char_no_save_recursive Find_Ped progress_to Find_Ped char_to Ped_donate

            0EFF: get_char_simplest_active_task Ped_donate id_to 3@ pointer_to 2@
            089F: get_actor Ped_donate pedtype_to 2@
            if and
                0EE4: locate_char_distance_to_char bum_man char $PLAYER_ACTOR radius 20.0
                0EE4: locate_char_distance_to_char bum_man char Ped_donate radius 10.0
                0019:   TIMERA > 35000
                not is_char_script_controlled Ped_donate
                80DF:   not actor Ped_donate driving
                3@ == 900
            then
                089F: get_actor Ped_donate pedtype_to 2@
                if or
                    2@ == 4
                    2@ == 5
                then
                    timera = 0
                    04C4: store_coords_to 2@ 3@ 4@ from_actor bum_man with_offset 0.0 1.0 0.0
                    04C4: store_coords_to 5@ 6@ 4@ from_actor bum_man with_offset 0.0 0.0 0.0
                    0E27: get_angle_from_two_coords 2@ 3@ and 5@ 6@ to 5@
                    0804: AS_actor Ped_donate walk_to 2@ 3@ 4@ angle 5@ radius 0.0 animation "SAX3" IFP "PedEventsMod" rate 4.0 LA 0 LX 0 LY 0 LF 0 LT -1
                    break
                end
            end

            if and
                timera > 5000
                not is_char_script_controlled Ped_donate
                Actor.Animation(Ped_donate) == "SAX3"
            then
                0613: 2@ = actor Ped_donate animation "SAX3" time
                if
                    2@ > 0.7
                then
                    if
                        8611:   not actor bum_man performing_animation "bum_thx"
                    then
                        gosub @Animation_donate
                    end
                    timera = 0
                end
            end
        end
        
    else
        break
    end
until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 120.0
04EF: release_animation "PedEventsMod"

gosub @Text_box_remove

if
    0EEA: locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 50.0
then
    if 056D:   actor bum_man defined
    then 01C2: remove_references_to_actor bum_man // Like turning an actor into a random pedestrian
    end
    if 03CA:   object obj_1 exists
    then 01C4: remove_references_to_object obj_1 // This object will now disappear when the player looks away
    end
else
    if 056D:   actor bum_man defined
    then 009B: destroy_actor bum_man
    end
    if 03CA:   object obj_1 exists
    then 0108: destroy_object obj_1
    end
end
//      ,      
if
    Event > 0
then
    07CC: set_player $PLAYER_CHAR can_enter_exit_vehicles 1
    06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 0
    0992: set_player $PLAYER_CHAR weapons_scrollable 1
    if not Money_render == -1
    then 0E2F: delete_render_object Money_render
    end
end

repeat
wait 0
until not locate_char_distance_to_coordinates $PLAYER_ACTOR pos coords_x coords_y coords_z radius 100.0

0A93: terminate_this_custom_script

//    
:Animation_donate
0615: define_AS_pack_begin 2@
0812: AS_actor -1 perform_animation "bum_thx" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1
0812: AS_actor -1 perform_animation "bum_idle" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1
0616: define_AS_pack_end 2@
0618: assign_actor bum_man to_AS_pack 2@
061B: remove_references_to_AS_pack 2@
return

:Animation_donate_EPico
0615: define_AS_pack_begin 2@
0812: AS_actor -1 perform_animation "bum_celeb" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1
0812: AS_actor -1 perform_animation "bum_thx" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1
0812: AS_actor -1 perform_animation "bum_idle" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1
0616: define_AS_pack_end 2@
0618: assign_actor bum_man to_AS_pack 2@
061B: remove_references_to_AS_pack 2@
return

:Animation_angry
0615: define_AS_pack_begin 2@
0812: AS_actor -1 perform_animation "bum_agres" IFP "PedEventsMod" framedelta 2.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1
0812: AS_actor -1 perform_animation "bum_idle" IFP "PedEventsMod" framedelta 2.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1
0616: define_AS_pack_end 2@
0618: assign_actor bum_man to_AS_pack 2@
061B: remove_references_to_AS_pack 2@
return

//  
:Event

//     
if and
    timerb > 500
    Event == 1
then
    model.Load(1212)
    038B: load_requested_models
    0E2E: create_render_object_to_char_bone $PLAYER_ACTOR model 1212 bone 24 offset 0.08 0.05 -0.04 rotation 0 0 0 store_to Money_render
    model.Destroy(1212)
    event = 2
    timerb = 0
end

//    ,   
if and
    timerb > 3000
    Event == 2
then
    0E2F: delete_render_object Money_render
    Money_render = -1
    06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 0
    0992: set_player $PLAYER_CHAR weapons_scrollable 1
    07CC: set_player $PLAYER_CHAR can_enter_exit_vehicles 1
    0109: player $PLAYER_CHAR money += -50
    if
        8611:   not actor bum_man performing_animation "bum_thx"
    then
        if
            donate_lvl == 3
        then
            gosub @Animation_donate_EPico
            donate_lvl = 0
        else
            gosub @Animation_donate
        end
    end
    event = 0
    timerb = 0
end
return

:Text_box_remove
if or
    0A2A:   text_box 'donat1' displayed
    0A2A:   text_box 'donat2' displayed
then
    03E6: remove_text_box
end
return